Skip to content

feat: [SDK-4324] add Capacitor SPM example demo project - #4

Merged
fadi-george merged 4 commits into
mainfrom
fadi/sdk-4324-create-spm-example-project
Apr 23, 2026
Merged

feat: [SDK-4324] add Capacitor SPM example demo project#4
fadi-george merged 4 commits into
mainfrom
fadi/sdk-4324-create-spm-example-project

Conversation

@fadi-george

@fadi-george fadi-george commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Description

One Line Summary

Add a new Capacitor + React example demo at examples/demo/ that uses Swift Package Manager on iOS, plus Package.swift fixes to align the plugin's SPM product name with Capacitor's derived name and switch to the official OneSignal/OneSignal-XCFramework package.

Screenshot 2026-04-23 at 2 02 31 PM

Details

Motivation

The repo only had a CocoaPods-based example (examples/demo_pods/). With Capacitor 7's first-class SPM support and the upcoming default switch to SPM, we need a maintained SPM-based reference app for testing and onboarding. While building the new demo I also hit two SDK-side issues that this PR fixes:

  • Package.swift declared the library as OneSignalCapacitorPlugin, but Capacitor's fixName rewrites onesignal-capacitor-plugin to OnesignalCapacitorPlugin, so SPM-based apps couldn't resolve the plugin product. Renamed both the package and the target to OnesignalCapacitorPlugin.
  • The SPM dependency pointed at a personal fork (nicklama/onesignal-xcframework-spm). Switched to the official OneSignal/OneSignal-XCFramework repo and widened the capacitor-swift-pm range to 7.0.0..<9.0.0.

Scope

  • Adds examples/demo/ (new SPM-based Capacitor + React + Ionic app) with iOS, Android, NSE, and Live Activity widget targets.
  • Updates examples/build.md with the new build/setup instructions for the SPM demo.
  • Updates Package.swift (product/target rename + dependency source) — required for any SPM consumer of the plugin, including the new demo.
  • Refactors the existing examples/demo_pods/ UI to share the same component patterns and useOneSignal hook shape as the new demo, and adds data-testid attributes for Appium. Behavior of demo_pods is otherwise unchanged.
  • No changes to the published SDK runtime under src/ or ios/Sources/OneSignalCapacitorPlugin/ source files (only the Swift package manifest changed).

Testing

Manual testing

  • Built the new examples/demo/ on iOS via SPM (bunx cap sync ios, opened in Xcode 16, ran on iPhone 16 simulator and a physical iPhone). Verified push registration, foreground/background notification click, IAM display + click, login/logout, alias/email/SMS/tag add+remove, outcomes, triggers, custom event, location permission, and Live Activity start/exit.
  • Built the new examples/demo/ on Android via bunx cap sync android and bunx cap run android against a Pixel 7 emulator (API 34). Verified push registration, notification click, and IAM flows.
  • Re-ran examples/demo_pods/ on iOS and Android to confirm the UI refactor still works against the same SDK build.
  • Confirmed bun run build + bun pack produce a tarball that installs cleanly into the new demo via the setup.sh flow.

Affected code checklist

  • Notifications
    • Display
    • Open
  • In-App Messaging
  • Public API changes (SPM product/target rename: OneSignalCapacitorPluginOnesignalCapacitorPlugin. Capacitor consumers don't import the product directly, but anyone pinning the SPM product name in a custom Package.swift will need to update.)

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed (example app + manifest changes; covered by manual testing on iOS and Android)
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

Made with Cursor

@linear

linear Bot commented Apr 23, 2026

Copy link
Copy Markdown
SDK-4324 Create spm example project

For capacitor

Comment thread examples/demo/android/build.gradle Outdated
Comment thread examples/demo/android/build.gradle Outdated
Comment on lines +1 to +3
VITE_ONESIGNAL_APP_ID=your_onesignal_app_id
VITE_ONESIGNAL_API_KEY=your_rest_api_key
VITE_E2E_MODE=false No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these get referenced anywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its for e2e and local testing

Comment on lines +252 to +262
OneSignal.InAppMessages.addEventListener('willDisplay', handleIamWillDisplay);
OneSignal.InAppMessages.addEventListener('didDisplay', handleIamDidDisplay);
OneSignal.InAppMessages.addEventListener('willDismiss', handleIamWillDismiss);
OneSignal.InAppMessages.addEventListener('didDismiss', handleIamDidDismiss);
OneSignal.InAppMessages.addEventListener('click', handleIamClick);
OneSignal.Notifications.addEventListener('click', handleNotificationClick);
OneSignal.Notifications.addEventListener('permissionChange', permissionHandler);
OneSignal.Notifications.addEventListener(
'foregroundWillDisplay',
handleForegroundWillDisplay,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: should event listeners be added before initialize? If something like permissions are changed before init completes, it might get missed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think initialize always has to be called first.

@fadi-george
fadi-george merged commit fdc6ba0 into main Apr 23, 2026
2 of 5 checks passed
@fadi-george
fadi-george deleted the fadi/sdk-4324-create-spm-example-project branch April 24, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants